package Models

import (
	"github.com/jinzhu/gorm"
	"time"
	Mysql "websocket_callback/Databases"
)

type User struct {
	Id        int
	Name      string
	LoginTime time.Time
	OutTime   time.Time
}

// 设置Test的表名为`test`
func (User) TableName() string {
	return "user"
}

func (this *User) Insert(tx *gorm.DB) (id int, err error) {
	result := tx.Create(&this)
	id = this.Id
	if result.Error != nil {
		err = result.Error
		return
	}
	return
}

func (this *User) Get(name string) (user User) {
	Mysql.DB.Where("name=?", name).Find(&user)
	return
}

func (this *User) Update() (err error) {
	result := Mysql.DB.Model(this).Where("Name = ?",this.Name).Select("OutTime").Update("OutTime",this.OutTime)

	if result.Error != nil {
		err = result.Error
		return
	}
	return
}
